<?php
declare(strict_types=1);

namespace App\Controller\Admin\V1\User;

use App\Controller\Admin\AdminController;
use App\Repositories\UserTagRepository;
use App\Request\UserTagRequest;

class TagController extends AdminController
{
    public function list(){
        $name = $this->request->input('name',null);
        $rows = $this->request->input('rows',10);
        $search=[];
        if($name){
            $search['name']=[
                'field' => 'name',
                'value' => $name,
                'method' => 'like'
            ];
        }
        $orderBy= [
            [
                'field' => 'id',
                'sort' => 'asc'
            ]
        ];
        $datas = UserTagRepository::getInstance()->getList('*',$search,['limit'=>$rows],$orderBy);
        return $this->response->success($datas);
    }

    public function detail(){
        $id = $this->request->input('id');
        $level = UserTagRepository::getInstance()->getById($id);
        return $this->response->success($level);
    }

    public function store(UserTagRequest $request){
        $return = UserTagRepository::getInstance()->store($request->all());
        if($return['success']){
            return $this->response->success($return['data']);
        }
        return $this->response->error(10011,$return['msg']);
    }

    public function delete(){
        $id = $this->request->input('id');
    }
}